/** mixin */
import { getIotControl, iotLogupdate } from "@/api/bedList";
import Push from 'push.js'
import { ysxShowLogin, ysxShowAreadevice } from "@/api/ysxroom";
import { generateMixed } from "@/utils"
import {
  getAccessToken,
} from "@/utils/accessToken";
import { mapGetters } from "vuex"
const audio1596 = require('../assets/mp3/1596.mp3')
const audio5196 = require('../assets/mp3/5196.mp3')
const audio8069 = require('../assets/mp3/8069.mp3')
const audio10686 = require('../assets/mp3/10686.mp3')
export default {
  data() {
    return{
      websocketList: null,
      lightList: [],
      pageDataList: [],
      scene_list: [],
      area_list: [],
      testdeviceactivename: "",
      dataList: [
        {
          id: 1,
          room_code: "多功能会议室",
        },
        {
          id: 2,
          room_code: "娱乐室1",
        },
        {
          id: 2,
          room_code: "娱乐室2",
        },
        {
          id: 3,
          room_code: "健康管理中心",
        },
        {
          id: 5,
          room_code: "老年人评估中心",
        },
        {
          id: 6,
          room_code: "适老化展示区",
        },
        {
          id: 6,
          room_code: "居家养老",
        },
        
        {
          id: 8,
          room_code: "办公室",
        },
        {
          id: 9,
          room_code: "男女浴室",
        },
      ],
      testlist: [],
      binddeviceList: [],
      audio: null,
      vensiData: {},
      closeTitle: "",
      lightDeviceList: [],
      binddeviceListLight: [],
      toiletList: [],
      sceneList: [],
      roomIndex: 0,
      roomTestIndex: 0,
      bedDeviceList: [],
      bedPageDataList: [],
      pageDataNum: false,
      notifications: {},
      notifiNum: sessionStorage.getItem('notifiNum') || 0,
      ysxBinddeviceList:[],
      jujiaobj: {
        value1: false,
        value2: false,
        value3: false,
        value4: false,
        onoff1: false,
        onoff2: false,
        onoff3: false,
        onoff4: false,
        color: 0,
        laorenmove: 0
      },
      jiehuobj: {
        laorenmove:0,
        color: 0
      },
      quanhuobj: {
        value1: false,
        value2: false,
        onoff1: false,
        onoff2: false,
        color: 0
      },
      zhongzhengobj: {
        value1: 1,
        value2: 0,
        value3: 0
      }
    }
  },
  computed: {
    ...mapGetters({
      adminType: "user/type",
      ysxAreaList: "websocket/ysxAreaList",
      ysxSceneList: "websocket/ysxSceneList"
    })
  },
  mounted() {
    if(getAccessToken()){
      getIotControl().then(() => {
        if(typeof(WebSocket) === "undefined"){
          alert("您的浏览器不支持WebSocket")
          return false
        }
        this.init();
        console.log(this.$route)
        if(this.$route.path == "/testdevice" || this.$route.path == "/ysxRoom") {
          
        }
      })
      this.audio = new Audio();
      this.closeTitle = localStorage.getItem("syonoff") && localStorage.getItem("syonoff") == 'off' ? "打开声音" : "关闭声音";
      //尉氏县网关登录
      ysxShowLogin({host_id: "40aa568e24d5"})
    }
    if(sessionStorage.getItem('notifiNum')) {
      this.notifiNum = Number(sessionStorage.getItem('notifiNum')) || 0;
    } else {
      sessionStorage.setItem('notifiNum', 0)
    }
  },
  created() {
    Push.Permission.request();
  },
  methods: {
    //关闭单个通知
    closeNotification(id) {
      this.notifications[id].close();
      delete this.notifications[id];
    },
    //关闭所有通知
    closeAllNotification(){
      // for (let key in _this.notifications) {
      //   _this.notifications[key].close();
      //   delete _this.notifications[key];
      // }
      this.$notify.closeAll()
    },
    //打开一个新的通知
    openMessageTips(message, callback){
      let _this = this;
      let notify = this.$notify({
        title: message.title,
        type: 'warning',
        customClass: "notificiation-wrap",
        showClose: false,
        duration: 0,
        offset: 140,
        dangerouslyUseHTMLString: true,
        message: this.$createElement('div', null,
          [
            this.$createElement('div', null, [this.$createElement('span', null, message.message)]),
            this.$createElement('div', null,
              [
                this.$createElement(
                  'button',
                  {
                    style: {
                      padding: '9px 15px',
                      textAlign: 'center',
                      textDecoration: 'none',
                      float: "right",
                      display: 'inline-block',
                      webkitTransitionDuration: '0.4s',
                      transitionDuration: '0.4s',
                      cursor: 'pointer',
                      backgroundColor: '#1890ff',
                      color: '#ffffff',
                      border: '1px solid #1890ff',
                      borderRadius: '2px',
                      fontSize: '12px'
                    },
                    on: {
                      mouseout: function(e) {
                        e.target.style.backgroundColor = '#1890ff';
                      },
                      mouseover: function(e) {
                        e.target.style.backgroundColor = '#46a6ff';
                      },
                      click: function() {
                        _this.closeNotification(message.messageId)
                        callback && callback()
                      }
                    }
                  },
                  "处理"
                )
              ]
            )
          ]
        ),
        duration: 0,
      });
      //将messageId和通知实例放入字典中
      this.notifications[message.messageId] = notify;
    },
    handleClosesy() {
      if(localStorage.getItem("syonoff") == 'on') {
        localStorage.setItem("syonoff", 'off')
        this.closeTitle = "打开声音"
      } else {
        localStorage.setItem("syonoff", 'on')
        this.closeTitle = "关闭声音"
      }
    },
    toGB2312(str) {
      return unescape(str.replace(/u/gi, '\\u').replace(/\\u/gi, '%u'));
    },
    init() {
      const _that = this;
      this.sendMsg("发送数据", res => {
        let data = eval("(" + res.data + ")");
        console.log(123123, res)
        if(!data){
          return false
        }
        // console.log('data', data)
        this.$store.dispatch("websocket/setInfoList", data.data);
        this.websocketList = data;
        //区域列表
        if(data.method == "area_list" && data.push_address == "show_area") {
          data.list.length && data.list.forEach(item => {
            if(item.area_name == "2F") {
              item.childlist.forEach(ite => {
                ite.device_list = [];
              })
              this.$store.dispatch("websocket/setYsxAreaList", item.childlist);
              item.childlist.length && item.childlist.forEach(ite => {
                // 获取区域内的设备
                ysxShowAreadevice({host_id: "40aa568e24d5", area_id: ite.area_id})
              })
            }
          })
        }
        //情景模式
        if(data.method == "scene_list" && data.push_address == "show_area") {
          data.list.length && this.$store.dispatch("websocket/setYsxSceneList", data.list);
        }
        //区域设备列表
        if(data.method == "area_device_list" && data.push_address == "show_area") {
          if(data.list.length && this.ysxAreaList.length){
            let num = 0;
            data.list.forEach(item => {
              if(item.onoff && item.onoff == 'on') {
                num++
              }
            })
            this.ysxAreaList.forEach(item => {
              if(data.list[0].area_id == item.area_id) {
                item.device_list = data.list.filter((item, i, arr) => {
                  return item.type != '0'
                });
                if(num != 0) {
                  item.light_status = "on";
                } else {
                  item.light_status = "off";
                }
              }
            })
            this.$store.dispatch("websocket/setYsxAreaList", this.ysxAreaList);
          }
          // if(data.list.length && this.pageDataList.length) {
          //   let num = 0;
          //   data.list.forEach(item => {
          //     if(item.onoff && item.onoff == 'on') {
          //       num++
          //     }
          //   })
          //   this.pageDataList.forEach(item => {
          //     //失能失智
          //     if(data.list[0].area_id == '0931289f4d1f4cb08785ea97be4ca5f7') {
          //       if(item.room_code == '211'){
          //         item.device_list = data.list;
          //         if(num != 0) {
          //           item.light_status = "on";
          //         } else {
          //           item.light_status = "off";
          //         }
          //       }
          //     }
          //     //居家自理
          //     if(data.list[0].area_id == '565c47c396204c49b8fed36841e87707') {
          //       if(item.room_code == '201'){
          //         item.device_list = data.list;
          //         if(num != 0) {
          //           item.light_status = "on";
          //         } else {
          //           item.light_status = "off";
          //         }
          //       }
          //     }
          //     //介助介护
          //     if(data.list[0].area_id == '0fd39fe6dfa0434fb175dc215e9bfb9f') {
          //       if(item.room_code == '210'){
          //         item.device_list = data.list;
          //         if(num != 0) {
          //           item.light_status = "on";
          //         } else {
          //           item.light_status = "off";
          //         }
          //       }
          //     }
          //   })
          //   this.$forceUpdate();
          // }
          data.list.length && data.list.forEach(item => {
            if(item.obj_id == '60A423FFFE233CEF01') {
              this.jujiaobj.value1 = item.onoff && item.onoff == 'on' ? true : false;
              this.jujiaobj.onoff1 = item.onoff && item.onoff == 'on' ? true : false;
            }
            if(item.obj_id == '60A423FFFE233CEF02') {
              this.jujiaobj.value2 = item.onoff && item.onoff == 'on' ? true : false;
              this.jujiaobj.onoff2 = item.onoff && item.onoff == 'on' ? true : false;
            }
            if(item.obj_id == '60A423FFFE233CEF03') {
              this.jujiaobj.value3 = item.onoff && item.onoff == 'on' ? true : false;
              this.jujiaobj.onoff3 = item.onoff && item.onoff == 'on' ? true : false;
            }
            if(item.obj_id == '60A423FFFE233CEF04') {
              this.jujiaobj.value4 = item.onoff && item.onoff == 'on' ? true : false;
              this.jujiaobj.onoff4 = item.onoff && item.onoff == 'on' ? true : false;
            }
            //失能失智房间
            if(item.obj_id == '60A423FFFE233D2601') {
              this.quanhuobj.value1 = item.onoff && item.onoff == 'on' ? true : false;
              this.quanhuobj.onoff1 = item.onoff && item.onoff == 'on' ? true : false;
            }
            if(item.obj_id == '60A423FFFE233D2602') {
              this.quanhuobj.value2 = item.onoff && item.onoff == 'on' ? true : false;
              this.quanhuobj.onoff2 = item.onoff && item.onoff == 'on' ? true : false;
            }
          })
        }
        //灯开关状态
        if(data.type == 1 && data.push_address == "show_area") {
          if(data.data.length && this.ysxBinddeviceList.length){
            this.ysxBinddeviceList.forEach((item, index) => {
              if(item.obj_id == data.data[0].devID || item.code == data.data[0].devID) {
                this.$set(this.ysxBinddeviceList[index], "light_status", data.data[0].status)
              }
            })
          }
          if(data.data.length) {
            this.ysxAreaList.length && this.ysxAreaList.forEach(item => {
              item.device_list.length && item.device_list.forEach(ite => {
                if(data.data[0].devID == ite.obj_id) {
                  ite.onoff = data.data[0].status && data.data[0].status == "on" ? "on" : "off";
                }
              })
            })
            this.ysxAreaList.length && this.ysxAreaList.forEach(item => {
              item.num = 0;
              item.device_list.length && item.device_list.forEach(ite => {
                if(ite.onoff == "on") {
                  item.num++
                }
              })
              if(item.num != 0) {
                item.light_status = "on";
              } else {
                item.light_status = "off";
              }
            })

            this.$store.dispatch("websocket/setYsxAreaList", this.ysxAreaList);
            //居家自理型
            if('60A423FFFE233CEF01' == data.data[0].devID){
              this.jujiaobj.value1 = data.data[0].status && data.data[0].status == 'on' ? true : false;
              this.jujiaobj.onoff1 = data.data[0].status && data.data[0].status == 'on' ? true : false;
            }
            if('60A423FFFE233CEF02' == data.data[0].devID){
              this.jujiaobj.value2 = data.data[0].status && data.data[0].status == 'on' ? true : false;
              this.jujiaobj.onoff2 = data.data[0].status && data.data[0].status == 'on' ? true : false;
            }
            if('60A423FFFE233CEF03' == data.data[0].devID){
              this.jujiaobj.value3 = data.data[0].status && data.data[0].status == 'on' ? true : false;
              this.jujiaobj.onoff3 = data.data[0].status && data.data[0].status == 'on' ? true : false;
            }
            if('60A423FFFE233CEF04' == data.data[0].devID){
              this.jujiaobj.value4 = data.data[0].status && data.data[0].status == 'on' ? true : false;
              this.jujiaobj.onoff4 = data.data[0].status && data.data[0].status == 'on' ? true : false;
            }
            //失能失智房间
            if('60A423FFFE233D2601' == data.data[0].devID){
              this.quanhuobj.value1 = data.data[0].status && data.data[0].status == 'on' ? true : false;
              this.quanhuobj.onoff1 = data.data[0].status && data.data[0].status == 'on' ? true : false;
            }
            if('60A423FFFE233D2602' == data.data[0].devID){
              this.quanhuobj.value2 = data.data[0].status && data.data[0].status == 'on' ? true : false;
              this.quanhuobj.onoff2 = data.data[0].status && data.data[0].status == 'on' ? true : false;
            }
          }
          if(this.pageDataList.length) {
            // let pageNum = 0;
            let num = 0;
            data.data.length && data.data.map(m => {
              this.pageDataList.map((item, index) => {
                let pageNum = item.pageNum || 0;
                this.$set(this.pageDataList[index], "light_status", "off");
                if(item.device_list && item.device_list.length > 0) {
                  item.device_list.map((i, d) => {
                    if(i.code == m.devID) {
                      this.$set(this.pageDataList[index].device_list[d], "onoff", m.status == 'on' ? 1 : 0);
                      if(m.status == 'on') {
                        this.pageDataList.length && this.$set(this.pageDataList[index], "pageNum", ++pageNum);
                      } else {
                        this.pageDataList.length && this.$set(this.pageDataList[index], "pageNum", --pageNum);
                      }
                    }
                  })
                }
              })
            })
            this.pageDataList.forEach((item, index) => {
              if(item.device_list && item.device_list.length > 0) {
                item.device_list.forEach((i, d) => {
                  if((i.onoff == "on" || i.onoff == 1) && i.type == 1) {
                    this.$set(this.pageDataList[index], "light_status", "on");
                  }
                })
              }
            })
            this.$nextTick(() => {
              this.ysxBinddeviceList.length && this.ysxBinddeviceList.map((item, index) => {
                if(item.type == 1 && (item.onoff == "on" || item.onoff == 1)) {
                  num++
                }
              })
              // if(num != 0) {
              //   this.pageDataList.length && this.$set(this.pageDataList[this.roomIndex], "light_status", "on");
              // } else {
              //   this.pageDataList.length && this.$set(this.pageDataList[this.roomIndex], "light_status", "off");
              // }
              // if(this.pageDataNum) {
              //   if(pageNum != 0) {
              //     this.pageDataList.length && this.$set(this.pageDataList[this.roomIndex], "light_status", "on");
              //   } else {
              //     this.pageDataList.length && this.$set(this.pageDataList[this.roomIndex], "light_status", "off");
              //   }
              // } 
            })
            this.$forceUpdate();
          }
        }
        //人体红外传感器
        if(data.type == 5 && data.push_address == "show_area") {
          if(data.data.length && data.data[0].devID == "000D6F0014F6D98B01") {
            if(data.data[0].is_exists == 1) {
              this.jujiaobj.laorenmove = 2;
            } else {
              if(this.jujiaobj.laorenmove == 2) {
                this.jujiaobj.laorenmove = 3;
              } else {
                this.jujiaobj.laorenmove = 1;
              }
              
            }
          }
        }

        //有无人 尿湿
        if((data.type == '11' || data.type == '12') && data.push_address == "show_area") {
          if(data.type == '11') {
            if(data.code == '5') { 
              //居家自理
              if(data.data.value == 0) { //有人
                this.jujiaobj.laorenmove = 4;
                this.jujiaobj.color = 1;
              } else {
                this.jujiaobj.laorenmove = 1;
                this.jujiaobj.color = 0;
              }
            }
            if(data.code == '6') {
              //介护
              if(data.data.value == 0) { //有人
                this.jiehuobj.laorenmove = 1;
                this.jiehuobj.color = 1;
              } else {
                this.jiehuobj.laorenmove = 2;
                this.jiehuobj.color = 0;
              }
            }
            
          }
          if(data.type == '12') {
            if(data.code == '5'){
              if(data.data.value == 1) { //尿湿
                this.jujiaobj.color = 2;
              } 
            }
            if(data.code == '6'){
              if(data.data.value == 1) { //尿湿
                this.jiehuobj.color = 2;
              } 
            }
            if(data.code == '7'){
              //失能 全护
              if(data.data.value == 1) { //尿湿
                this.quanhuobj.color = 2;
              } else if(data.data.value == 0){
                this.quanhuobj.color = 0;
              }
            }
            
          }
        }

        //心率 呼吸率 有人检测
        if(data.type == '13' && data.push_address == "show_area") {
          if(data.data.length){
            data.data.forEach(item => {
              if(item.id == 2) {
                this.zhongzhengobj.value1 = item.value;
              }
              if(item.id == 3) {
                this.zhongzhengobj.value2 = item.value;
              }
              if(item.id == 4) {
                this.zhongzhengobj.value3 = item.value;
              }
            })
          }
        }

        if(data.type == 2) {
          data.data.map(item => {
            let location = "";
            if(data.push_address == 'show_area') {
              if(item.devID == "5C0272FFFEA7CF8401") {
                location = "请注意查看，居家自理室房间报警器响了"
              } else {
                location = "请注意查看，房间报警器响了"
              }
            } else {
              if(item.location) {
                if(item.location.place == '-1') {
                  location = item.location.building_name + '-' + item.location.floor_code + '-' + item.location.room_code + "卫生间报警器响了"
                } else {
                  location = item.location.building_name + '-' + item.location.floor_code + '-' + item.location.room_code + "报警器响了"
                }
              } else {
                location = "请注意查看，房间报警器响了"
              }
            }
            
            Push.create("请注意查看，房间报警器响了", {
              body: location,
              requireInteraction: true,
              // icon: './assets/qr_logo/lqr_logo.png',
              timeout: 60000,
            });
            // this.Notification({
            //   title: '请注意查看，房间报警器响了',
            //   dangerouslyUseHTMLString: true,
            //   message: location,
            //   type: 'warning',
            //   customClass: "notificiation-wrap",
            //   // duration: 60000,
            //   onClose: () => {
            //     this.audio.pause();
            //     this.audio.currentTime = 0.0; 
            //   }
            // });
            this.openMessageTips({
              title: location,
              message: '请注意查看，房间报警器响了',
              messageId: generateMixed(5)
            },() => {
              _that.audio.pause();
              _that.audio.currentTime = 0.0; 
              data.log_id && iotLogupdate("get", {id: data.log_id})
            })
          })
          if(!localStorage.getItem("syonoff") || localStorage.getItem("syonoff") == 'on') {
            setTimeout(()=>{
              _that.audio.src = audio1596;
              _that.audio.loop = true;
              _that.audio.play();
            }, 100);
          }
        }
        if(data.type == 3) {
          data.data.map(item => {
            let location = "";
            if(data.push_address == 'show_area') {
              
              if(item.status == "on"){
                if(item.devID == '5C0272FFFEA7C8DD01') {
                  location = "居家自理室房间门打开了"
                } else if(item.devID == "5C0272FFFEA60DB501") {
                  location = "介助介护培训室房间门打开了"
                } else {
                  location = "房间门打开了"
                }
              } else {
                if(item.devID == '5C0272FFFEA7C8DD01') {
                  location = "居家自理室房间门关闭了"
                } else if(item.devID == "5C0272FFFEA60DB501") {
                  location = "介助介护培训室房间门关闭了"
                } else {
                  location = "房间门关闭了"
                }
              }
            } else {
              if(item.location) {
                if(item.status == "on") {
                  location = item.location.building_name + '-' + item.location.floor_code + '-' + item.location.room_code + "房间门打开了"
                } else {
                  location = item.location.building_name + '-' + item.location.floor_code + '-' + item.location.room_code + "房间门关闭了"
                }
              } else {
                location = "房间门" + item.status == "on" ? "打开了" : "关闭了"
              }
            }
            
            Push.create(location, {
              body: location,
              requireInteraction: true,
              timeout: 60000,
            });
            // this.Notification({
            //   title: location,
            //   dangerouslyUseHTMLString: true,
            //   message: location,
            //   type: 'warning',
            //   customClass: "notificiation-wrap",
            //   duration: 60000,
            // });
            this.openMessageTips({
              title: location,
              message: location,
              messageId: generateMixed(5)
            }, () => {
              data.log_id && iotLogupdate("get", {id: data.log_id})
            })
          })
        }
        if(data.type == 4) {
          if(!localStorage.getItem("syonoff") || localStorage.getItem("syonoff") == 'on') {
            setTimeout(()=>{
              _that.audio.src = audio1596;
              _that.audio.loop = true;
              _that.audio.play();
            }, 100);
          }
          data.data.map(item => {
            let location = "";
            if(data.push_address == 'show_area') {
              location = "请注意查看，可燃气体打开了"
            } else {
              if(item.location) {
                location = item.location.building_name + '-' + item.location.floor_code + '-' + item.location.room_code + "可燃气体打开了"
              } else{
                location = "可燃气体打开了"
              }
            }
            Push.create("可燃气体报警", {
              body: location,
              requireInteraction: true,
              timeout: 60000,
            });
            this.openMessageTips({
              title: location,
              message: '可燃气体报警',
              messageId: generateMixed(5)
            },() => {
              _that.audio.pause();
              _that.audio.currentTime = 0.0; 
              data.log_id && iotLogupdate("get", {id: data.log_id})
            })
          })
        }
        if(data.type == 5) {
          // setTimeout(()=>{
          //   this.audio.src = audio1596;
          //   this.audio.loop = true;
          //   this.audio.play();
          // }, 100);
          data.data.map(item => {
            let location = "";
            if(data.push_address == 'show_area') {
              if(item.devID == "000D6F0014F6D98B01") {
                location = item.is_exists == 1 ? "请注意查看，居家自理室卫生间检测有人" : "请注意查看，居家自理室卫生间检测无人"
              }else {
                location = item.is_exists == 1 ? "请注意查看，检测有人" : "请注意查看，检测无人"
              }
            } else {
              if(item.location) {
                if(item.status == 1) {
                  location = item.location.building_name + '-' + item.location.floor_code + '-' + item.location.room_code + "请注意查看，检测有人"
                } else {
                  location = item.location.building_name + '-' + item.location.floor_code + '-' + item.location.room_code + "请注意查看，检测无人"
                }
              } else {
                location = item.status == 1 ? "请注意查看，检测有人" : "请注意查看，检测无人"
              }
            }
            Push.create("人体红外传感器报警", {
              body: location,
              requireInteraction: true,
              // icon: './assets/qr_logo/lqr_logo.png',
              timeout: 60000,
            });
            this.openMessageTips({
              title: location,
              message: '人体红外传感器报警',
              messageId: generateMixed(5)
            }, () => {
              data.log_id && iotLogupdate("get", {id: data.log_id})
            })
            // this.Notification({
            //   title: location,
            //   dangerouslyUseHTMLString: true,
            //   message: '人体红外传感器报警',
            //   type: 'warning',
            //   customClass: "notificiation-wrap",
            //   duration: 60000,
            //   // onClose: () => {
            //   //   this.audio.pause();
            //   //   this.audio.currentTime = 0.0; 
            //   // }
            // });
          })
          localStorage.setItem("toiletList", JSON.stringify(data.data));
          if(!data.is_test) {
            this.toiletList = data.data;
          }
        }
        if(data.type == 6) {
          if(!localStorage.getItem("syonoff") || localStorage.getItem("syonoff") == 'on') {
            setTimeout(()=>{
              _that.audio.src = audio1596;
              _that.audio.loop = true;
              _that.audio.play();
            }, 100);
          }
          data.data.map(item => {
            let location = "";
            if(data.push_address == 'show_area') {
              location = "请注意查看，居家自理室烟雾报警";
            } else {
              if(item.location) {
                location = item.location.building_name + '-' + item.location.floor_code +'-' + item.location.room_code + "烟雾报警";
              } else {
                location = "请注意查看，烟雾报警"
              }
            }
            Push.create("烟雾报警", {
              body: location,
              requireInteraction: true,
              // icon: './assets/qr_logo/lqr_logo.png',
              timeout: 60000,
            });
            // this.Notification({
            //   title: item.location ? item.location.building_name + '-' + item.location.floor_code +'-' + item.location.room_code + "烟雾报警" : "烟雾报警",
            //   dangerouslyUseHTMLString: true,
            //   message: '烟雾报警',
            //   type: 'warning',
            //   customClass: "notificiation-wrap",
            //   duration: 60000,
            //   onClose: () => {
            //     this.audio.pause();
            //     this.audio.currentTime = 0.0; 
            //   }
            // });
            this.openMessageTips({
              title: location,
              message: '烟雾报警',
              messageId: generateMixed(5)
            },() => {
              _that.audio.pause();
              _that.audio.currentTime = 0.0; 
              data.log_id && iotLogupdate("get", {id: data.log_id})
            })
          })
        }
        if(data.type == 7) {
          data.data.map(item => {
            let location = "";
            if(data.push_address == "show_area") {
              if(item.percent == 100) {
                if(item.devID == '14B457FFFED01E9201' || item.devID == '14B457FFFECFFDAE01') {
                  location = "失能失智照护培训室房间窗帘打开" + item.percent + "%";
                } else if(item.devID == '14B457FFFED01A0301' || item.devID == '14B457FFFED01D6801') {
                  location = "居家自理室房间窗帘打开" + item.percent + "%";
                } else {
                  location = "窗帘打开" + item.percent + "%";
                }
              } else if(item.percent == 0) {
                if(item.devID == '14B457FFFED01E9201' || item.devID == '14B457FFFECFFDAE01') {
                  location = "失能失智照护培训室房间窗帘关闭" + item.percent + "%";;
                } else if(item.devID == '14B457FFFED01A0301' || item.devID == '14B457FFFED01D6801') {
                  location = "居家自理室房间窗帘关闭" + item.percent + "%";
                } else {
                  location = "窗帘关闭" + item.percent + "%";
                }
              }
            } else {
              if(item.location) {
                if(item.percent == 100) {
                  location = item.location.building_name + '-' + item.location.floor_code + '-' + item.location.room_code + "窗帘打开了"
                } else if(item.percent == 0){
                  location = item.location.building_name + '-' + item.location.floor_code + '-' + item.location.room_code + "窗帘关闭了"
                }
              } else {
                if(item.percent == 100) {
                  location = "窗帘打开了"
                } else if(item.percent == 0) {
                  location = "窗帘关闭了"
                }
              }
            }
            
            if(item.percent == 100 || item.percent == 0) {
              Push.create("窗帘", {
                body: location,
                requireInteraction: true,
                // icon: './assets/qr_logo/lqr_logo.png',
                timeout: 60000,
              });
              // this.Notification({
              //   title: location,
              //   dangerouslyUseHTMLString: true,
              //   message: '窗帘',
              //   type: 'warning',
              //   customClass: "notificiation-wrap",
              //   duration: 60000,
              // });
              this.openMessageTips({
                title: location,
                message: '窗帘',
                messageId: generateMixed(5)
              }, () => {
                data.log_id && iotLogupdate("get", {id: data.log_id})
              })
            } 
          })
          
        }
        if(data.type == 8) {
          if(!localStorage.getItem("syonoff") || localStorage.getItem("syonoff") == 'on') {
            setTimeout(()=>{
              this.audio.src = audio1596;
              this.audio.loop = true;
              this.audio.play();
            }, 100);
          }
          data.data.map(item => {
            let location = "";
            if(data.push_address == "show_area"){
              location = "请注意查看，漏水报警了";
            } else {
              if(item.location) {
                location = item.location.building_name + '-' + item.location.floor_code +'-' + item.location.room_code + "漏水报警了"
              } else {
                location = "请注意查看，漏水报警了";
              }
            }
            Push.create("漏水报警", {
              body: location,
              requireInteraction: true,
              timeout: 60000,
            });
            this.openMessageTips({
              title: location,
              message: '漏水报警',
              messageId: generateMixed(5)
            },() => {
              _that.audio.pause();
              _that.audio.currentTime = 0.0; 
              data.log_id && iotLogupdate("get", {id: data.log_id})
            })
          })
        }
        if(data.type == 10) {
          data.data.map(item => {
            let location = "";
            if(data.push_address == "show_area"){
              location = "请注意查看，安防报警";
            } else {
              if(item.location) {
                location = item.location.building_name + '-' + item.location.floor_code +'-' + item.location.room_code + "安防报警"
              } else {
                location = "请注意查看，安防报警";
              }
            }
            Push.create("安防报警", {
              body: location,
              requireInteraction: true,
              // icon: './assets/qr_logo/lqr_logo.png',
              timeout: 60000,
            });
            this.openMessageTips({
              title: location,
              message: '安防报警',
              messageId: generateMixed(5)
            },() => {
              _that.audio.pause();
              _that.audio.currentTime = 0.0; 
              data.log_id && iotLogupdate("get", {id: data.log_id})
            })
            // this.Notification({
            //   title: item.location ? item.location.building_name + '-' + item.location.floor_code +'-' + item.location.room_code + "安防报警" : "安防报警",
            //   dangerouslyUseHTMLString: true,
            //   message: '安防报警',
            //   customClass: "notificiation-wrap",
            //   type: 'warning',
            //   duration: 60000,
            //   onClose: () => {
            //     this.audio.pause();
            //     this.audio.currentTime = 0.0; 
            //   }
            // });
          })
          if(!localStorage.getItem("syonoff") || localStorage.getItem("syonoff") == 'on') {
            setTimeout(()=>{
              _that.audio.src = audio1596;
              _that.audio.loop = true;
              _that.audio.play();
            }, 100);
          }
        }
        if(data.type == '11') {
          const _this = this;
          let location = "";
          if(data.push_address == 'show_area') {
            if(data.code == '6') {
              if(data.data.value == 0) {
                location = '';
              } else {
                location = '介助介护培训室床位无人'
              }
            } else if(data.code == '5'){
              if(data.data.value == 0) {
                location = '';
              } else {
                location = '居家自理室床位无人'
              }
            }
          } else {
            if(data.code == '6') {
              if(data.data.value == 0) {
                location = '';
              } else {
                location = '介助介护培训室床位无人'
              }
            } else if(data.code == '5'){
              if(data.data.value == 0) {
                location = '';
              } else {
                location = '居家自理室床位无人'
              }
            } else {
              if(data.place) {
                if(data.place.place == '0') {
                  location = (data.place.building_name && this.toGB2312(data.place.building_name) || "") + '-' + data.place.floor_code + '-' + data.place.room_code + '-';
                } else {
                  location = (data.place.building_name && this.toGB2312(data.place.building_name) || "") + '-' + data.place.floor_code + '-' + data.place.room_code + '-00' + data.place.place + '-';
                }
              } 
              if(data.data.value == 0) {
                location = "";
              } else {
                location = location + "床位无人"
              }
            }
          }
          
          if(location != "") {
            Push.create("床垫报警", {
              body: location,
              requireInteraction: true,
              timeout: 60000,
            });
            setTimeout(function(){
              _this.openMessageTips({
                title: location,
                message: '床垫报警',
                messageId: generateMixed(5)
              },() => {
                _that.audio.pause();
                _that.audio.currentTime = 0.0; 
                data.log_id && iotLogupdate("get", {id: data.log_id})
              })
            }, 0)
          }
          if(!localStorage.getItem("syonoff") || localStorage.getItem("syonoff") == 'on') {
            setTimeout(()=>{
              _that.audio.src = audio1596;
              _that.audio.loop = true;
              _that.audio.play();
            }, 100);
          }
        }
        if(data.type == '12') {
          const _this = this;
          let location = "";
          if(data.push_address == 'show_area') {
            if(data.code =='6') {
              if(data.data.value == 1) {
                location = '介助介护培训室床位尿湿'
              } else {
                location = '';
              }
            } else if(data.code == '7'){
              if(data.data.value == 1) {
                location = '失能失智照护培训室床位尿湿'
              } else {
                location = '';
              }
            }
          } else {
            if(data.code =='6') {
              if(data.data.value == 1) {
                location = '介助介护培训室床位尿湿'
              } else {
                location = '';
              }
            } else if(data.code == '7'){
              if(data.data.value == 1) {
                location = '失能失智照护培训室床位尿湿'
              } else {
                location = '';
              }
            } else {
              if(data.place) {
                if(data.place.place == '0') {
                  location = (data.place.building_name && this.toGB2312(data.place.building_name) || "") + '-' + data.place.floor_code + '-' + data.place.room_code + '-';
                } else {
                  location = (data.place.building_name && this.toGB2312(data.place.building_name) || "") + '-' + data.place.floor_code + '-' + data.place.room_code + '-00' + data.place.place + '-';
                }
              } 
              if(data.data.value == 1) {
                location = location + "床位尿湿"
              } else {
                location = "";
              }
            }
          }
          if(location != "") {
            Push.create("床垫报警", {
              body: location,
              requireInteraction: true,
              timeout: 60000,
            });
            setTimeout(function(){
              _this.openMessageTips({
                title: location,
                message: '床垫报警',
                messageId: generateMixed(5)
              },() => {
                _that.audio.pause();
                _that.audio.currentTime = 0.0; 
                data.log_id && iotLogupdate("get", {id: data.log_id})
              })
            }, 0)
          }
          if(!localStorage.getItem("syonoff") || localStorage.getItem("syonoff") == 'on') {
            setTimeout(()=>{
              _that.audio.src = audio1596;
              _that.audio.loop = true;
              _that.audio.play();
            }, 100);
          }
        }
        if(data.method == "scene_list" && !data.push_address) {
          this.scene_list = data.list;
        }
        if(data.method == "area_list" && !data.push_address) {
          this.area_list = data.list;
          this.testdeviceactivename = data.list[0].area_name;
          let list = []
          data.list.length > 0 && data.list.map(item => {
            if(item.childlist.length > 0) {
              item.childlist.map(ite => {
                list.push(ite)
              })
            }
          })
          console.log(this.dataList, list)
          list.map((item, index) => {
            this.dataList[index] && Object.assign(this.dataList[index], item)
            this.dataList[index] && this.$set(this.dataList[index], 'light_status', 'off')
            this.$set(list[index], 'light_status', 'off')
          })
        }

        if(data.method == "area_device_list" && !data.push_address) {
          this.binddeviceList = data.list;
        }

        if(data.method == "device_status" && data?.data[0]?.device_type && data?.data[0]?.device_type == "9") {
          this.vensiData = data.data[0]
        }

        if(data.method == 'scene_detail' && !data.push_address) {
          this.sceneList = data?.list[0]?.action_list || []
        }

        if(data.method == 'bed_device') {
          this.bedDeviceList = data;
          this.bedPageDataList.length && this.bedPageDataList.forEach((item, index) => {
            if(item.room_code == data?.place?.room_code) {
              item.bed_list.forEach((ite, idx) => {
                if(Number(ite.bed_code) == Number(data?.place?.place) || Number(ite.bed_code) == Number(data?.place?.bed_code)) {
                  if(data.type == '11') {
                    this.$set(this.bedPageDataList[index].bed_list[idx], "bed_status_id", data.data.id)
                    this.$set(this.bedPageDataList[index].bed_list[idx], "bed_status_value", data.data.value)
                  }
                  if(data.type == '12') {
                    this.$set(this.bedPageDataList[index].bed_list[idx], "bed_wets_id", data.data.id)
                    this.$set(this.bedPageDataList[index].bed_list[idx], "bed_wets_value", data.data.value)
                  }
                }
              })
            }
          })
        }
        
        if(data.type == 1) {
          if(data.push_address == "show_area") {
            
            this.$forceUpdate();
          } else {
            this.lightList = data.data;
            let num = 0;
            let pageNum = 0;
            this.binddeviceListLight.length && this.binddeviceListLight.map((item, index) => {
              if(item.code == data.data[0].devID) {
                this.$set(this.binddeviceListLight[index], "onoff", data.data.length && data.data[0].status || 'off')
              }
            })
            this.lightDeviceList = data.data;
            data.data.length && data.data.map(m => {
              this.pageDataList.map((item, index) => {
                if(item.device_list && item.device_list.length > 0) {
                  item.device_list.map((i, d) => {
                    if(i.code == m.devID) {
                      this.$set(this.pageDataList[index].device_list[d], "onoff", m.status == 'on' ? 1 : 0);
                      if(m.status == 'on') {
                        pageNum++
                      }
                    }
                  })
                }
              })
            })
            this.$nextTick(() => {
              this.binddeviceListLight.length && this.binddeviceListLight.map((item, index) => {
                if(item.type == 1 && (item.onoff == "on" || item.onoff == 1)) {
                  num++
                }
              })
              if(num != 0) {
                this.pageDataList.length && this.$set(this.pageDataList[this.roomIndex], "light_status", "on");
              } else {
                this.pageDataList.length && this.$set(this.pageDataList[this.roomIndex], "light_status", "off");
              }
              if(this.pageDataNum) {
                if(pageNum != 0) {
                  this.pageDataList.length && this.$set(this.pageDataList[this.roomIndex], "light_status", "on");
                } else {
                  this.pageDataList.length && this.$set(this.pageDataList[this.roomIndex], "light_status", "off");
                }
              } 
            })
            
            this.$forceUpdate();
          }
        }
      })
    }
  }
}
